<?php

require_once "ModelBase.php";
class Test extends TTEvent_Table_Abstract
{
    protected $_name = 'tamtay_event';
    protected $_primary = 'eid';
    
    public function va()
        {
            $db = $this->getSlaveDB(); 
            $sql="select * from tamtay_event limit 0,30";
            return  $db->fetchAll($sql);
        }
    public function getAllComment()
        {
            $db = $this->getSlaveDB();
            $sql="SELECT * FROM tamtay_comment";
            return $db->fetchAll($sql);
        }
    public function getAllNetwork(){
            $db = $this->getSlaveDB();
            $sql="SELECT name,nwid FROM mytt_network";
            return $db->fetchAll($sql);
    }   
    public function getNetworkByType($ntid,$search){
            $db = $this->getSlaveDB();
            $name=$search['name'];
            $city=(int)$search['city'];
            $sql="SELECT name,nwid FROM mytt_network WHERE ntid=".$ntid;

            if($city>0){
            $sql=$sql." AND cityID=".$city;
            }
            if($name!=""){
            $name=str_replace(" ","%",$name);
            $sql=$sql." AND name LIKE '%".$name."%'";    
            }
            return $db->fetchAll($sql);
    }
    public function getCities(){
            $db = $this->getSlaveDB();
            $sql="SELECT * FROM cities WHERE nid=1";
            return $db->fetchAll($sql); 
    }
    public function saveInfo($name,$phone,$address,$eid){
        $sql="INSERT INTO tamtay_event_member2 (name,phone,address,eid) VALUES(?,?,?,?)";
        $db = $this->getSlaveDB();
        $db->query($sql,Array($name,$phone,$address,$eid));
    }
    public function checkCost($eid){
        $sql="SELECT `cost`,`limit` FROM tamtay_event_ticket WHERE eid=?";
        $db = $this->getSlaveDB();
        return $db->fetchRow($sql,Array($eid));
    }
}